package com.zhxi.gulimall.coupon.controller;

import com.netflix.ribbon.proxy.annotation.ResourceGroup;
import com.zhxi.common.utils.PageUtils;
import com.zhxi.common.utils.R;
import com.zhxi.gulimall.coupon.entity.CouponEntity;
import com.zhxi.gulimall.coupon.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 优惠券信息
 *
 * @Author: zhxi
 * @Email: 664480310@qq.com
 * @Date: 2024-08-19 17:48:34
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("coupon/coupon")
@RefreshScope
public class CouponController {
    @Autowired
    private CouponService couponService;
    @Value("${user.name}")
    String name;
    @Value("${user.age}")
    String age;

    @GetMapping("/member/list")
    public R memberCoupons() {
        CouponEntity coupon = new CouponEntity();
        coupon.setCouponName("ssssssssssssss");
        return R.ok().put("coupons", Arrays.asList(coupon));
    }

    @GetMapping("/test")
    public String test() {
        return age + "sssssssssssssss" + name;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = couponService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        CouponEntity coupon = couponService.getById(id);
        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CouponEntity coupon) {
        couponService.save(coupon);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CouponEntity coupon) {
        couponService.updateById(coupon);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        couponService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
